#include <iostream>

using namespace std;

int n;
const int N = 15;
bool st[N];
int a[N];

int ret = 0;

void dfs(int pos)
{
    if(pos == n + 1)
    {
        ret++;
    }
    for(int i = 1;i <= n;i++)
    {
        if(st[i])
        {
            continue;
        }
        if(st[a[i]])
        {
            continue;
        }
        st[i] = true;
        dfs(pos + 1);
        st[i] = false;
    }
}

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    dfs(1);
    cout << ret << endl;
    return 0;
}